//////////////////////////////////////////////////////////////////////////////////
//
//	DoD MG Extra Recoil
//		- Version 1.2
//		- 12.16.2006
//		- diamond-optic
//
//////////////////////////////////////////////////////////////////////////////////
//
// Information:
//
// 	- Adds extra recoil to undeployed MGs
//
// Credits:
//
//   	- Original idea came from TatsuSaisei's dod_mg_mustdeploy
//	  plugin, just I didnt want to totally disable undeployed
//	  MGs, i just wanted to make it a wee bit more difficult.
//	  
//
// CVARs: 
//
//	dod_mg_extrarecoil "1" 		//Turn ON(1)/OFF(0)
//
// Changelog:
//
//	- 11.02.2006 Version 1.0
//		Initial Release
//
//	- 12.03.2006 Version 1.1
//		Tweaked recoil.. Increased Pitch and Yaw, decreased Roll
//		Increased Max angle difference from 90 to 120 Yaw
//
//	- 12.16.2006 Version 1.2
//		Improved method of catching MG fire
//		Made whole thing more effecient :-)
//
//////////////////////////////////////////////////////////////////////////////////

#include <amxmodx>
#include <dodfun>
#include <fakemeta>

new p_cvar

public plugin_init()
{
	register_plugin("DoD MG Extra Recoil", "1.2", "AMXX DoD Team")
	
	//plugin stats public cvar
	register_cvar("dod_mg_extrarecoil_stats", "1.2", FCVAR_SERVER|FCVAR_SPONLY)
	
	p_cvar = register_cvar("dod_mg_extrarecoil", "1")
	
	register_event("CurWeapon","recoil_check","be","1=1","2=17","2=18","2=21","3>0")
}

public recoil_check(id)
{
	if(!is_user_alive(id) || !is_user_connected(id) || !get_pcvar_num(p_cvar))
		return PLUGIN_CONTINUE
		
	if(pev(id,pev_button) & IN_ATTACK && !dod_is_deployed(id))
		{			
		new Float:fVec[3]
		pev(id,pev_punchangle, fVec)
		fVec[0] += random_float(-20.0,20.0)
		fVec[1] += random_float(-20.0,20.0)
		fVec[2] += random_float(-5.0,5.0)
		
		if(fVec[0] > 90.0)	
			fVec[0] = 90.0
		else if(fVec[0] < -90.0)	
			fVec[0] = -90.0
			
		if(fVec[1] > 120.0)	
			fVec[1] = 120.0
		else if(fVec[1] < -120.0)	
			fVec[1] = -120.0
			
		if(fVec[2] > 120.0)	
			fVec[2] = 120.0
		else if(fVec[2] < -120.0)
			fVec[2] = -120.0
		
		set_pev(id,pev_punchangle,fVec)
		
		message_begin(MSG_ONE_UNRELIABLE,get_user_msgid("ScreenShake"),{0,0,0},id)
		write_short(1<<14) //ammount 
		write_short(1<<12) //lasts this long 
		write_short(2<<12) //frequency
		message_end()
		}
		
	return PLUGIN_CONTINUE
}